using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CrystalWand:Weapon {

	public CrystalWand(WeaponData stat) : base(stat) { }

	public override Projectile ShootSingleProjectile(Vector2 position,Angle direction,ProjectileData projectile,Dictionary<int,int> consumedAmmo) {
		if(projectile==null) return null;

		Vector2 firingPosition = position;
		for(int i = 0;i<100;i++) {
			Vector2 newPosition = firingPosition+new Vector2(Random.Range(-1f,1f),Random.Range(-1f,1f));
			int cnt = Physics2D.OverlapAreaNonAlloc(newPosition+new Vector2(-0.1f,-0.1f),newPosition+new Vector2(0.1f,-0.1f),Utility.colliderBuffer);
			bool spotFound = true;
			for(int j = 0;j<cnt;j++) {
				if(Utility.colliderBuffer[j].tag=="Wall") spotFound=false;
			}
			if(spotFound) {
				firingPosition=newPosition;
				break;
			}
		}

		Angle shootAngle = new Angle(owner.targetPosition-firingPosition);

		Projectile projectileShot = Projectile.Create(projectile,firingPosition,shootAngle,this,consumedAmmo,ProjectileFireCallback);
		return projectileShot;

	}

	override protected void ProjectileFiringEventHandler(object _sender,ProjectileEventArgs e) {
		base.ProjectileFiringEventHandler(_sender,e);
		if(!IfReactFireEvent(_sender,e)) return;
		Projectile sender = _sender as Projectile;
		sender.stat.damage.AddMultiply(0.5f,-100);
	}
}